<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/include/taglibs.jsp"%>
<script type="text/javascript">

$(document).ready(function(){
	<c:if test="${param.returnCd=='0000' }">alert('수정했습니다');</c:if>	
	$("#code").focus();
});

//삭제 
function deleteData(dt,pcode){
	if(!confirm("삭제하시겠습니까?")){
		return false;
	}
	location.href="./coma103T.do?code_no="+dt+"&code_p_no="+pcode;
}

var maxOrder = 0;
<c:if test="${list !=null && fn:length(list)>0 }">
maxOrder = ${list[fn:length(list)-1].code_order };
</c:if>

//순서변경
function changeOrder(index, condition){
	var code= $("#code_no_"+index).val();
	var order= $("#code_order_"+index).val();
	
	var sum= Number(index)+condition;
// 	alert($("#code_no_"+sum).val());
	if(sum<0){
		return false;
	}

	if(maxOrder==sum){
		return false;
	}
// 	alert($("#code_no_"+sum).val());
	var ch_code= $("#code_no_"+sum).val();
	var ch_order= $("#code_order_"+sum).val();
// 	alert("code="+code+", order="+order+" , chcode="+ch_code +", chor= "+ch_order);
// alert("./coma104T.do?code_no="+code+"&code_order="+ch_order+"&ch_code_no="+ch_code+"&ch_code_order="+order+"&code_p_no=${param.code_p_no }");
	location.href="./coma104T.do?code_no="+code+"&code_order="+ch_order+"&ch_code_no="+ch_code+"&ch_code_order="+order+"&code_p_no=${param.code_p_no }";
}
</script>

	<table width="800" border="0" cellspacing="1" cellpadding="2"
		CLASS="class_admin_table_nocolor">
		<tr>
			<td height="25" width="150"><font color="BROWN">코드관리 ▶
					코드구분</font></td>
			<td height="25" width="650" align="left">&nbsp;</td>
		</tr>
	</table>
	<table width="800" border="0" cellspacing="1" cellpadding="2"
		CLASS="class_admin_table">
		<tr height="25" CLASS="class_admin_table_head">
			<TD align="center" width="100">번호</td>
			<TD align="center" width="100">코드고유번호</td>
			<TD align="center" width="100">코드</td>
			<TD align="center" width="*">코드명</td>
			<TD align="center" width="100">순서변경</td>
			<TD align="center" width="100">삭제</td>
		</tr>
<c:if test="${list !=null && fn:length(list)>0 }">
	<c:forEach var="map" items="${list}" varStatus="status">
		<form action="./coma102T.do" method="post">
			<input name="code_no" type="hidden" value="${map.code_no }"/>
			<input name="code_p_no" type="hidden" value="${map.code_p_no }"/>
			<input name="code_no_${status.index }" id="code_no_${status.index }" type="hidden" value="${map.code_no }"/>
			<input name="code_order_${status.index }" id="code_order_${status.index }" type="hidden" value="${map.code_order }"/>
			<tr height="25" class="class_admin_table_blank">
				<td align="center">${status.count}</td>
				<td align="center">
					<c:if test="${!empty param.code_p_no && ''!=param.code_p_no}">
						${map.code_no}
					</c:if>
					<c:if test="${empty param.code_p_no || ''==param.code_p_no}">
						<a href="?code_p_no=${map.code_no}">${map.code_no}</a>
					</c:if>
				</td>
				<td align="left">
					<input name="code" value="${map.code }" />
				</td>
				<td align="center">
					<input name="code_nm" value="${map.code_nm }" />
				</td>
				<td align="center">
					<a href="#" onclick="changeOrder('${status.index }',-1);return false;">위로</a> 
					<a href="#" onclick="changeOrder('${status.index }',1);return false;">아래로</a>
				</td>
				<td align="center">
					<input type=button class=btn	onclick="if( confirm('수정하시겠습니까?')) this.form.submit();" value="수정">
					<input type=button class=btn	onclick="deleteData('${map.code_no }','${map.code_p_no }');return false;" value="삭제">
				</td>
			</tr>
		</form>

	</c:forEach>
</c:if>
	</table>
	<BR>
	<table width="800" border="0" cellspacing="1" cellpadding="2"
		CLASS="class_admin_table_nocolor">
		<tr>
			<td height="25" width="250"><font color="BROWN">코드관리 ▶
					새코드구분 만들기</font></td>
			<td height="25" width="550" align="left">&nbsp;</td>
		</tr>
	</table>
	<form action="./coma101T.do" method='post' >
		<input type="hidden" name="code_p_no" value="${param.code_p_no }">
		<input type="hidden" name="code_depth" value="<c:if test="${!empty param.code_p_no && ''!=param.code_p_no}">1</c:if><c:if test="${empty param.code_p_no || ''==param.code_p_no}">0</c:if>">
		
			<table width="800" border="0" cellspacing="1" cellpadding="2"
				class="class_admin_table">
		
					<tr height="25">
						<td align="center" width="100" class="class_admin_table_head">코드</td>
						<td width="200" class="class_admin_table_blank">
							<input type="text" name="code" id="code" size="20" maxlength="100"></td>
						<td align="center" width="100" class="class_admin_table_head">*코드명</td>
						<td width="200" class="class_admin_table_blank"><input
							type="text" name="code_nm" size="20" maxlength="100"></td>
						<td align="center" width="200" class="class_admin_table_blank"><input
							type='submit' name='submit' value='구 분 등 록'></td>
					</tr>
			</table>
	</form>

<c:if test="${!empty param.code_p_no && ''!=param.code_p_no}">
	<input type=button class=btn	onclick="location.href='./coma101Q.do'" value="목록">
</c:if>

